//
//  MyAdActionsCell.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/22/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit

final class MyAdActionsCell: UITableViewCell, ConfigurableCell {
 
    
    lazy var buttonsStack: UIStackView = {
        let stack = UIStackView()
        stack.axis = .horizontal
        stack.alignment = .fill
        stack.distribution = .fillEqually
        stack.spacing = 8
        return stack
    }()
    
    lazy var editBtn: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = .lightBlueColor
        btn.setTitleColor(.blueColor, for: .normal)
        btn.layer.cornerRadius = 15
        btn.setTitle("Редактировать", for: .normal)
        return btn
    }()
    
    lazy var stopBtn: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = .lightBlueColor
        btn.setTitleColor(.blueColor, for: .normal)
        btn.layer.cornerRadius = 15
        btn.setTitle("Остановить", for: .normal)
        return btn
    }()
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.addViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func addViews () {
        addSubview(buttonsStack)
        layoutMargins = .zero
        directionalLayoutMargins = .zero
        
        buttonsStack.addArrangedSubview(stopBtn)
        buttonsStack.addArrangedSubview(editBtn)

        buttonsStack.snp.makeConstraints { (make) in
            make.bottom.leading.trailing.equalToSuperview().inset(16)
            make.top.equalToSuperview().inset(30)
            make.height.equalTo(44)
        }
    }
    
    func configure(data: MyAdViewModel.MyAdEditItem?, index: Int) {
        self.stopBtn.setTitle(data!.isPaused ? "Включить" : "Остановить", for: .normal)
    }
    
    func returnData() -> MyAdViewModel.MyAdEditItem? {  return nil }
}
